/*
 * XDefaultAction.java, created on Oct 25, 2005
 * 
 * Copyright (c) 2005 - 2007
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.xfc.components;

import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.KeyStroke;

/**
 *
 *
 * @author Devon Carew
 */
public abstract class XDefaultAction
	extends AbstractAction
{
	private Icon largeIcon;
	
	/**
	 * 
	 */
	public XDefaultAction()
	{
		
	}

	/**
	 * @param command
	 */
	public XDefaultAction(String command)
	{
		this();
		
		setCommand(command);
	}
	
	/**
	 * @return the action command
	 */
	public String getCommand()
	{
		return (String)getValue(ACTION_COMMAND_KEY);
	}
	
	/**
	 * @param command
	 */
	public void setCommand(String command)
	{
		putValue(ACTION_COMMAND_KEY, command);
	}
	
	/**
	 * @return Returns the icon.
	 */
	public Icon getSmallIcon()
	{
		return (Icon)getValue(SMALL_ICON);
	}
	
	/**
	 * @param icon The icon to set.
	 */
	public void setSmallIcon(Icon icon)
	{
		putValue(SMALL_ICON, icon);
	}
	
	/**
	 * An alias for <code>getSmallIcon()</code>.
	 * 
	 * @return a small icon
	 * @see #getSmallIcon()
	 */
	public Icon getIcon()
	{
		return getSmallIcon();
	}
	
	/**
	 * @param icon
	 */
	public void setIcon(Icon icon)
	{
		setSmallIcon(icon);
	}
	
	/**
	 * @return Returns the text.
	 */
	public String getText()
	{
		return (String)getValue(NAME);
	}
	
	/**
	 * @param text The text to set.
	 */
	public void setText(String text)
	{
		putValue(NAME, text);
	}
	
	/**
	 * @return Returns the toolTipText.
	 */
	public String getToolTip()
	{
		return (String)getValue(SHORT_DESCRIPTION);
	}
	
	/**
	 * @param toolTipText The toolTipText to set.
	 */
	public void setToolTip(String toolTipText)
	{
		putValue(SHORT_DESCRIPTION, toolTipText);
	}
	
	/**
	 * @return Returns the accelerator.
	 */
	public KeyStroke getAccelerator()
	{
		return (KeyStroke)getValue(ACCELERATOR_KEY);
	}
	
	/**
	 * @param accelerator The accelerator to set.
	 */
	public void setAccelerator(KeyStroke accelerator)
	{
		putValue(ACCELERATOR_KEY, accelerator);
	}
	
	/**
	 * @return Returns the largeIcon.
	 */
	public Icon getLargeIcon()
	{
		return largeIcon;
	}
	
	/**
	 * @param largeIcon The largeIcon to set.
	 */
	public void setLargeIcon(Icon largeIcon)
	{
		this.largeIcon = largeIcon;
	}
	
	/**
	 * @return Returns the longDescription.
	 */
	public String getLongDescription()
	{
		return (String)getValue(LONG_DESCRIPTION);
	}
	
	/**
	 * @param longDescription The longDescription to set.
	 */
	public void setLongDescription(String longDescription)
	{
		putValue(LONG_DESCRIPTION, longDescription);
	}
	
	/**
	 * @return Returns the mnemonic.
	 */
	public Integer getMnemonic()
	{
		return (Integer)getValue(MNEMONIC_KEY);
		
//		Integer keyCode = (Integer)getValue(MNEMONIC_KEY);
//		
//		return keyCode == null ? 0 : keyCode.intValue();
	}
	
	/**
	 * @param mnemonic The mnemonic to set.
	 */
	public void setMnemonic(Integer mnemonic)
	{
		//MenuShortcut ms = new MenuShortcut(KeyEvent.VK_A, false);
		
		// TODO: get this working -
		//putValue(MNEMONIC_KEY, ms);
		//putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_X));
		//putValue(MNEMOKEY, new Integer(KeyEvent.VK_X));
		
		putValue(MNEMONIC_KEY, mnemonic);
	}
	
	public void setEnabled(boolean newValue)
	{
		boolean oldValue = super.isEnabled();
		super.setEnabled(newValue);
		firePropertyChange("enabled", Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
	}
	
}
